package com.longteng.java.web;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by tianqing.wang
 * DATE : 2018/4/1
 * TIME : 下午3:38
 * PROJECT : web-lesson
 * PACKAGE : com.longteng.java.web
 *
 * @author <a href="mailto:celeskyking@163.com">tianqing.wang</a>
 */
@RestController
public class PostController {




    @PostMapping(value = "/test/post.json",produces = {"application/json;charset=utf-8"})
    public ResponseData post(@RequestBody RequestData requestData){
        System.out.println("接收到请求:"+requestData);
        ResponseData responseData = new ResponseData();
        if(requestData.getName().equals("tianqing.wang")){
            responseData.setRet(true);
            responseData.setResult("hello,world");
        }else{
            responseData.setRet(false);
            responseData.setRetMsg("名字必须是tianqing.wang");
        }
        return responseData;
    }



    public static class RequestData{
        private String name;

        private String age;

        private String type;


        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        @Override
        public String toString() {
            return new ToStringBuilder(this)
                    .append("name", name).append("\n")
                    .append("age", age).append("\n")
                    .append("type", type).append("\n")
                    .toString();
        }
    }


    public static class ResponseData {


        private boolean ret;

        private String retMsg;

        private String result;


        public boolean isRet() {
            return ret;
        }

        public void setRet(boolean ret) {
            this.ret = ret;
        }

        public String getRetMsg() {
            return retMsg;
        }

        public void setRetMsg(String retMsg) {
            this.retMsg = retMsg;
        }

        public String getResult() {
            return result;
        }

        public void setResult(String result) {
            this.result = result;
        }
    }


}
